package bishi.haikang;

public class demo1 {
    public static void main(String[] args) {
        System.out.println(verb("hello@163.com", "email"));
        System.out.println(verb("13812345678", "phone"));
        System.out.println(verb("431900199401052699", "idcard"));
        System.out.println(verb("牛小二", "name"));


    }

    public static String verb(String rawString, String type) {
        if (rawString == null || rawString == "") {
            return "";
        } else {
            StringBuilder ret = new StringBuilder();

            if ("email".equals(type)) {
                int right = rawString.indexOf("@");
                int left = 1;
                for (int i = 0; i < rawString.length(); i++) {
                    if (i >= left && i < right - 1) {
                        ret.append("*");
                    } else {
                        ret.append(rawString.charAt(i));
                    }
                }
                return ret.toString();


            } else if ("phone".equals(type)) {
                int left = 3;
                int right = 7;
                for (int i = 0; i < rawString.length(); i++) {
                    if (i < left || i >= right) {
                        ret.append(rawString.charAt(i));
                    } else {
                        ret.append("*");
                    }
                }


                return ret.toString();

            }else if("idcard".equals(type)) {
                int left = 1;
                int right = rawString.length()-2;
                for (int i = 0; i < rawString.length(); i++) {
                    if (i < left || i >= right) {
                        ret.append(rawString.charAt(i));
                    } else {
                        ret.append("*");
                    }
                }


                return ret.toString();
            }else if("name".equals(type)) {
                int left = 1;
                for (int i = 0; i < rawString.length(); i++) {
                    if (i < left ) {
                        ret.append(rawString.charAt(i));
                    } else {
                        ret.append("*");
                    }
                }
                return ret.toString();
            }
            return rawString;

        }

    }
}